package com.sino.second.struts2;

import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.sino.bean.TblZhuanjiarukuxinxibiao;
import com.sino.bean.Xk;
import com.sino.business.IBasicInfoService;
import com.sino.business.IPatentManageService;
import com.sino.business.IStaticDataService;
import com.sino.model.BasicInfoModel;
import com.sino.model.ExpertModel;
import com.sino.second.bean.TblSystemparam;
import com.sino.second.business.IReviewService;
import com.sino.second.business.service.BaseDataService;
import com.sino.second.exception.BusinessException;
import com.sino.second.model.ExpertsReviewModel;
import com.sino.second.model.SystemparamModel;
import com.sino.second.model.XmReviewResults;
import com.sino.second.model.XmpszbModel;
import com.sino.util.CreatQueryCondition;
import com.sino.util.PageControl;
import com.sino.util.SysParameter;

public class Review1Action extends ActionSupport {
	private SystemparamModel systemparamModel;

	private String beginTime;

	private String lastTime;

	private IStaticDataService staticDateService;// 基础数据

	private IPatentManageService ipatentManageService;// 专利管理

	private IReviewService review1ServiceImpl;// 专家评审ID

	private BaseDataService baseDataService;// 基础数据1;

	private IBasicInfoService basicInfoService;// 基本信息

	private List<BasicInfoModel> basicInfoList;// 项目基本信息

	private List<TblZhuanjiarukuxinxibiao> zhuanjiaList;

	private BasicInfoModel basicinfoModel;// 基本信息基础类

	private List<XmpszbModel> xpszbList;// 项目评审指标

	private String pageStr;// 分页字符串

	private String xmTitle;// 项目标题

	private int pageRow;// 分页行

	private String operAction;// 操作ACTION

	private String page;// 当前页

	private String xmId;// 项目ID

	private String zjId;// 专家ID

	private String xkId;

	private String zlid;

	private Integer FBh;

	private String xm;

	List<ExpertsReviewModel> ermList;

	private List<XmReviewResults> review1List;

	private String year;

	private String ispass;

	private Integer count1;

	private Integer xmCount;

	private Integer fsCount;

	/**
	 * 项目基本信息
	 */
	private List hyList;

	private List xkList;

	private List zlTypeList;

	private List zlType1List;

	private List xkzlList;

	private List areaList;

	private List flztList;

	private List qxkwList;

	/**
	 * 评审专业列表
	 * 
	 * @return
	 */
	public String review1XkList() {
		List<Xk> hyList = this.staticDateService.findXkList();
		operAction = "review1infoList.action";
		return SUCCESS;
	}

	/**
	 * 初审项目信息
	 * 
	 * @return
	 */
	public String expertsreview1XmList() {

		ExpertModel em = (ExpertModel) ActionContext.getContext().getSession()
				.get("expertModel");
		if (true != em.isFirstReview()) {
			throw new BusinessException("sys.firstReview.exception");

		}
		CreatQueryCondition creatQueryCondition = new CreatQueryCondition();// 条件查询类
		creatQueryCondition.initializtion(ServletActionContext.getRequest());
		String hqlWhere = " isqualified=1 and basicinfo.xk.id= '"
				+ em.getSysZhuanyemamcId() + "' and basicinfo.year="
				+ SysParameter.CURRENT_YEAR;// 通过项目、合格项目
		if (creatQueryCondition.getHqlWhere().length() > 1) {
			hqlWhere += " and " + creatQueryCondition.getHqlWhere();
		}
		PageControl pageControl = new PageControl();// 翻页控制类
		// CreatQueryCondition creatQueryCondition = new
		// CreatQueryCondition();// 条件查询类
		pageControl.setPage(page);// 设置当前页
		pageControl.setPageSize(20);// 设置每页显示的记录数量
		pageControl.setRowCount(this.getIpatentManageService()
				.getBasicInfoPageCount(hqlWhere, "0000"));// 设置总记录数
		int startRow = (pageControl.getPage() - 1) * pageControl.getPageSize();// 开始行数
		int pageSize = pageControl.getPageSize();// 每页显示的数量
		this.setPageRow(startRow);
		pageStr = pageControl.getPageInfo(
				"expertsreview1XmList.action?review2=1", creatQueryCondition
						.getCondition());
		basicInfoList = this.getIpatentManageService().getBasicInfoPageList(
				startRow, pageSize, hqlWhere, "0000");// 分页查询考生信息
		xmTitle = SysParameter.CURRENT_YEAR + "年北京市发明专利基本信息列表";
		this.setBasicInfoList(basicInfoList);
		this.setPageStr(pageStr);
		return "success";

	}

	/**
	 * 项目分数显示
	 * 
	 * @return
	 */
	public String viewReview1Xm() {
		this.setHyList(this.getStaticDateService().findHyList());
		this.setXkList(this.getStaticDateService().findXkList());
		this.setZlTypeList(this.getStaticDateService().findZlTypeList());
		this.setZlType1List(this.getStaticDateService().findZlType1List());
		this.setXkzlList(this.getStaticDateService().findXkzlList());
		this.setAreaList(this.getStaticDateService().findAreaList());
		this.setFlztList(this.getStaticDateService().findFlztList());
		this.setQxkwList(this.getStaticDateService().findQxkwList());
		this.setBasicinfoModel(this.getBasicInfoService().findBasicinfoById(
				xmId));
		xpszbList = this.getBaseDataService().getXmpszb();
		ermList = this.getReview1ServiceImpl().findReviewsList(xmId,
				new Integer(zjId));
		return this.SUCCESS;
	}

	/**
	 * 项目分数显示
	 * 
	 * @return
	 */
	public String viewExcepertsReview1Xm() {
		this.setHyList(this.getStaticDateService().findHyList());
		this.setXkList(this.getStaticDateService().findXkList());
		this.setZlTypeList(this.getStaticDateService().findZlTypeList());
		this.setZlType1List(this.getStaticDateService().findZlType1List());
		this.setXkzlList(this.getStaticDateService().findXkzlList());
		this.setAreaList(this.getStaticDateService().findAreaList());
		this.setFlztList(this.getStaticDateService().findFlztList());
		this.setQxkwList(this.getStaticDateService().findQxkwList());
		this.setBasicinfoModel(this.getBasicInfoService().findBasicinfoById(
				xmId));
		xpszbList = this.getBaseDataService().getXmpszb();
		ermList = this.getReview1ServiceImpl().findReviewsList(xmId,
				new Integer(zjId));
		return this.SUCCESS;
	}

	/**
	 * 保存初审项目
	 * 
	 * @return
	 */
	public String saveReview1Xm() {
		this.getReview1ServiceImpl().saveOrUpdateReviews(ermList);
		return this.SUCCESS;
	}

	/**
	 * 专家评审分数信息列表
	 * 
	 * @return
	 */
	public String listReviewByExperts() {
		ExpertModel em = (ExpertModel) ActionContext.getContext().getSession()
				.get("expertModel");

		ermList = this.getReview1ServiceImpl().findReviewXmListByZjId(
				em.getFBh(), " tx1.year=" + SysParameter.CURRENT_YEAR);
		this.setYear(SysParameter.CURRENT_YEAR);
		zjId = em.getFBh().toString();
		return this.SUCCESS;
	}

	/**
	 * 专家评审结果表
	 * 
	 * @return
	 */
	public String listReviewResultsByExperts() {
		ExpertModel em = (ExpertModel) ActionContext.getContext().getSession()
				.get("expertModel");
		String hqlWhere = "txj1.basicinfo.xk.id= '" + em.getSysZhuanyemamcId()
				+ "' and txj1.year=" + SysParameter.CURRENT_YEAR;
		review1List = this.getReview1ServiceImpl().findReviewResultsList(
				hqlWhere);
		this.setYear(SysParameter.CURRENT_YEAR);
		return this.SUCCESS;
	}

	public BasicInfoModel getBasicinfoModel() {
		return basicinfoModel;
	}

	public void setBasicinfoModel(BasicInfoModel basicinfoModel) {
		this.basicinfoModel = basicinfoModel;
	}

	public IBasicInfoService getBasicInfoService() {
		return basicInfoService;
	}

	public void setBasicInfoService(IBasicInfoService basicInfoService) {
		this.basicInfoService = basicInfoService;
	}

	public String getOperAction() {
		return operAction;
	}

	public void setOperAction(String operAction) {
		this.operAction = operAction;
	}

	public IStaticDataService getStaticDateService() {
		return staticDateService;
	}

	public void setStaticDateService(IStaticDataService staticDateService) {
		this.staticDateService = staticDateService;
	}

	public IPatentManageService getIpatentManageService() {
		return ipatentManageService;
	}

	public void setIpatentManageService(
			IPatentManageService ipatentManageService) {
		this.ipatentManageService = ipatentManageService;
	}

	public String getXmId() {
		return xmId;
	}

	public void setXmId(String xmId) {
		this.xmId = xmId;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public List<BasicInfoModel> getBasicInfoList() {
		return basicInfoList;
	}

	public void setBasicInfoList(List<BasicInfoModel> basicInfoList) {
		this.basicInfoList = basicInfoList;
	}

	public String getPageStr() {
		return pageStr;
	}

	public void setPageStr(String pageStr) {
		this.pageStr = pageStr;
	}

	public int getPageRow() {
		return pageRow;
	}

	public void setPageRow(int pageRow) {
		this.pageRow = pageRow;
	}

	public String getXmTitle() {
		return xmTitle;
	}

	public void setXmTitle(String xmTitle) {
		this.xmTitle = xmTitle;
	}

	public String getZjId() {
		return zjId;
	}

	public void setZjId(String zjId) {
		this.zjId = zjId;
	}

	public IReviewService getReview1ServiceImpl() {
		return review1ServiceImpl;
	}

	public void setReview1ServiceImpl(IReviewService review1ServiceImpl) {
		this.review1ServiceImpl = review1ServiceImpl;
	}

	public BaseDataService getBaseDataService() {
		return baseDataService;
	}

	public void setBaseDataService(BaseDataService baseDataService) {
		this.baseDataService = baseDataService;
	}

	public List<XmpszbModel> getXpszbList() {
		return xpszbList;
	}

	public void setXpszbList(List<XmpszbModel> xpszbList) {
		this.xpszbList = xpszbList;
	}

	public List getAreaList() {
		return areaList;
	}

	public void setAreaList(List areaList) {
		this.areaList = areaList;
	}

	public List getFlztList() {
		return flztList;
	}

	public void setFlztList(List flztList) {
		this.flztList = flztList;
	}

	public List getHyList() {
		return hyList;
	}

	public void setHyList(List hyList) {
		this.hyList = hyList;
	}

	public List getQxkwList() {
		return qxkwList;
	}

	public void setQxkwList(List qxkwList) {
		this.qxkwList = qxkwList;
	}

	public List getXkList() {
		return xkList;
	}

	public void setXkList(List xkList) {
		this.xkList = xkList;
	}

	public List getXkzlList() {
		return xkzlList;
	}

	public void setXkzlList(List xkzlList) {
		this.xkzlList = xkzlList;
	}

	public List getZlType1List() {
		return zlType1List;
	}

	public void setZlType1List(List zlType1List) {
		this.zlType1List = zlType1List;
	}

	public List getZlTypeList() {
		return zlTypeList;
	}

	public void setZlTypeList(List zlTypeList) {
		this.zlTypeList = zlTypeList;
	}

	public List<ExpertsReviewModel> getErmList() {
		return ermList;
	}

	public void setErmList(List<ExpertsReviewModel> ermList) {
		this.ermList = ermList;
	}

	public List<XmReviewResults> getReview1List() {
		return review1List;
	}

	public void setReview1List(List<XmReviewResults> review1List) {
		this.review1List = review1List;
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getXkId() {
		return xkId;
	}

	public void setXkId(String xkId) {
		this.xkId = xkId;
	}

	public List<TblZhuanjiarukuxinxibiao> getZhuanjiaList() {
		return zhuanjiaList;
	}

	public void setZhuanjiaList(List<TblZhuanjiarukuxinxibiao> zhuanjiaList) {
		this.zhuanjiaList = zhuanjiaList;
	}

	public String getZlid() {
		return zlid;
	}

	public void setZlid(String zlid) {
		this.zlid = zlid;
	}

	public Integer getFBh() {
		return FBh;
	}

	public void setFBh(Integer bh) {
		FBh = bh;
	}

	public String getXm() {
		return xm;
	}

	public void setXm(String xm) {
		this.xm = xm;
	}

	/**
	 * xyw
	 * 
	 * @return
	 */
	public String findXmByXkId() {
		String HQL = " year = " + SysParameter.CURRENT_YEAR;
		int countcount = this.review1ServiceImpl.findReviewXkId(HQL);
		if (countcount > 0) {
			return INPUT;
		} else {
			ExpertModel em = (ExpertModel) ActionContext.getContext()
					.getSession().get("expertModel");
			String hqlWhere = " basicinfo.year=" + SysParameter.CURRENT_YEAR;// 通过项目、合格项目
			String hqlwhere = "year=" + SysParameter.CURRENT_YEAR;
			PageControl pageControl = new PageControl();// 翻页控制类
			pageControl.setPage(page);// 设置当前页
			pageControl.setPageSize(20);// 设置每页显示的记录数量
			pageControl.setRowCount(this.getReview1ServiceImpl()
					.findReviewXmCount(xkId, hqlWhere));// 设置总记录数
			int startRow = (pageControl.getPage() - 1)
					* pageControl.getPageSize();// 开始行数
			int pageSize = pageControl.getPageSize();// 每页显示.的数量
			pageStr = pageControl.getPageInfo("findXmByXkId.action?xkId="
					+ xkId, "");
			basicInfoList = this.getReview1ServiceImpl().findReviewXmList(
					startRow, pageSize, xkId, hqlWhere);// 分页查询考生信息
			xmTitle = SysParameter.CURRENT_YEAR + "年北京市发明专利预审信息列表";
			count1 = this.review1ServiceImpl.findZjpsfpCountByXmpsmcId(
					SysParameter.FIRSTREVIEW, xkId, hqlwhere);
			xmCount = this.review1ServiceImpl.findXmCountByXkId(xkId);
			fsCount = this.review1ServiceImpl.findFsCountByXkId(xkId);
			this.setBasicInfoList(basicInfoList);
			this.setPageStr(pageStr);
			this.setPageRow(startRow);
			return this.SUCCESS;
		}
	}

	/**
	 * xyw 根据项目ID，查出所评该项目所有的专家。并求出专家ID。
	 * 
	 */
	public String findZhuanJiaByZjId() {

		zhuanjiaList = this.review1ServiceImpl.findZhuanjiaByZlid(zlid);
		if (null == zhuanjiaList) {
			return INPUT;
		} else {
			TblZhuanjiarukuxinxibiao zhuanjia1 = zhuanjiaList.get(0);
			return this.SUCCESS;
		}

	}

	/**
	 * xyw控制时间
	 * 
	 * @return
	 */

	public String ControlTime() {
		TblSystemparam t = new TblSystemparam();
		TblSystemparam t2 = new TblSystemparam();
		t.setParamName("beginTime");
		t.setParamValue(this.getBeginTime());
		t2.setParamName("endTime");
		t2.setParamValue(this.getLastTime());
		this.review1ServiceImpl.saveOrUpdateTime(t,t2);
		return SUCCESS;
	}
	
	public String ControlTime2() {
		TblSystemparam t = new TblSystemparam();
		TblSystemparam t2 = new TblSystemparam();
		t.setParamName("beginTime");
		t.setParamValue("");
		t2.setParamName("endTime");
		t2.setParamValue("");
		this.review1ServiceImpl.saveOrUpdateTime(t,t2);
		return SUCCESS;
	}
	
	

	public String getIspass() {
		return ispass;
	}

	public void setIspass(String ispass) {
		this.ispass = ispass;
	}

	public Integer getCount1() {
		return count1;
	}

	public void setCount1(Integer count1) {
		this.count1 = count1;
	}

	public Integer getXmCount() {
		return xmCount;
	}

	public void setXmCount(Integer xmCount) {
		this.xmCount = xmCount;
	}

	public Integer getFsCount() {
		return fsCount;
	}

	public void setFsCount(Integer fsCount) {
		this.fsCount = fsCount;
	}

	public SystemparamModel getSystemparamModel() {
		return systemparamModel;
	}

	public void setSystemparamModel(SystemparamModel systemparamModel) {
		this.systemparamModel = systemparamModel;
	}

	public String getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}

	public String getLastTime() {
		return lastTime;
	}

	public void setLastTime(String lastTime) {
		this.lastTime = lastTime;
	}

}
